// 新开一行，防止代码拼接连在一起
#ifndef COMPILE_TEST // 后期在执行compile程序替换时带上-D COMPILE_TEST
#include "header.cpp"
#endif

class Answer
{
public:
    int calculateMinimumHP(vector<vector<int>> &dungeon)
    {
        int m = dungeon.size(), n = dungeon[0].size();
        vector<vector<int>> dp(m + 1, vector<int>(n + 1, INT_MAX));
        // 以某一个位置为起点,到达终点所需最小健康值
        dp[m][n - 1] = 0;

        for (int i = m - 1; i >= 0; i--)
        {
            for (int j = n - 1; j >= 0; j--)
            {
                dp[i][j] = min(dp[i + 1][j], dp[i][j + 1]) - dungeon[i][j];
                if (dp[i][j] < 0)
                    dp[i][j] = 0;
            }
        }
        return dp[0][0] + 1;
    }
};
void test_1()
{
    vector<vector<int>> v = {{-2, -3, 3}, {-5, -10, 1}, {10, 30, -5}};
    int ret = Solution().calculateMinimumHP(v);
    if (ret == Answer().calculateMinimumHP(v))
    {
        cout << "测试用例1通过" << endl;
    }
    else
    {
        cerr << "测试用例1没通过" << endl;
    }
}
void test_2()
{
    vector<vector<int>> v = {{0}};
    int ret = Solution().calculateMinimumHP(v);
    if (ret == Answer().calculateMinimumHP(v))
    {
        cout << "测试用例2通过" << endl;
    }
    else
    {
        cerr << "测试用例2没通过" << endl;
    }
}
int main()
{
    test_1();
    test_2();

    return 0;
}